Allow text fragments in same-document navigations This CL lifts the restriction on text fragments in the specific case of a same-document navigation initiated by an origin that's same-origin with the current document. In this case, the two documents already have full access to each other's content so text fragments present no risk. Enabling them allows using anchor links to text-fragments on the current page as well as allowing coordinating origins to pass a text-fragment into an iframe. To do this, we update DocumentLoader's |is_same_origin_navigation_| member on same-document navigations (and we rename it to be more specific that the initiator is same-origin or browser). We also make another small adjustment in allowing text fragments to be invoked on replacement navigations (e.g. location.replace) which don't create a new history entry. This was simply an unintentional omission in the implementation. Change-Id: Id82f46294b87d12d6a7355e0f7e4936e7fae75d6 Bug: 1198668 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2811999 Commit-Queue: David Bokan <bokan@chromium.org> Reviewed-by: Matt Falkenhagen <falken@chromium.org> Reviewed-by: Nicolás Peña Moreno <npm@chromium.org> Reviewed-by: Robert Flack <flackr@chromium.org> Cr-Commit-Position: refs/heads/master@{#875755} 
diff --git a/scroll-to-text-fragment/scroll-to-text-fragment-same-doc.html b/scroll-to-text-fragment/scroll-to-text-fragment-same-doc.html index ff33952..378e373 100644 --- a/scroll-to-text-fragment/scroll-to-text-fragment-same-doc.html +++ b/scroll-to-text-fragment/scroll-to-text-fragment-same-doc.html 
@@ -23,25 +23,33 @@  });  }   +function reset() { + window.location.hash = ""; + window.scrollTo(0, 0); +} +  function runTest() {  promise_test(t => new Promise(resolve => { + reset();  window.location.href = "#:~:text=test";  requestAnimationFrame(function() {  checkScroll(resolve);  });  }).then(position => { - assert_equals(position, 'top'); + assert_equals(position, 'text');  assert_equals(window.location.href.indexOf(':~:'), -1, 'Expected fragment directive to be stripped from the URL.'); - }), 'Test that a text fragment directive cannot be activated on a same-document navigation'); + }), 'Activated for same-document window.location setter');    promise_test(t => new Promise(resolve => { - window.location.href = "#text"; + reset(); + window.location.replace("#:~:text=test");  requestAnimationFrame(function() {  checkScroll(resolve);  });  }).then(position => {  assert_equals(position, 'text'); - }), 'Sanity check that the text element can be navigated by element ID'); + assert_equals(window.location.href.indexOf(':~:'), -1, 'Expected fragment directive to be stripped from the URL.'); + }), 'Activated for same-document window.location.replace');  }  </script>  <style>